/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.upms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.params.EnabledParam;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.*;
import com.mt.roll.upms.params.MenuParam;
import com.mt.roll.upms.params.MenuQueryParam;
import com.mt.roll.upms.params.RoleMenuParam;
import com.mt.roll.upms.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 平台菜单控制器
 *
 * @author jiff
 * @date 2018/11/14
 * @since 1.0
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_UPMS + "menu")
@Slf4j
@Api(value = "平台菜单管理", tags = "平台菜单管理接口", hidden = false)
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;


    @PostMapping(value = "get")
    @ApiOperation(value = "获取菜单")
    private R<MenuVo> get(@Validated @RequestBody IdParam idParam) {
        return menuService.get(idParam);
    }

    @PostMapping(value = "list")
    @ApiOperation(value = "获取菜单列表")
    private R<List<MenuVo>> list(@Validated @RequestBody MenuQueryParam menuQueryParam) {
        return menuService.list(menuQueryParam);
    }

    @PostMapping(value = "page")
    @ApiOperation(value = "获取分页菜单")
    private R<PageVo<MenuVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody MenuQueryParam menuQueryParam) {
        return menuService.page(menuQueryParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody MenuParam menuParam) {
        return menuService.add(menuParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody MenuParam menuParam) {
        return menuService.update(menuParam);
    }

    @PostMapping(value = "enabled")
    @ApiOperation(value = "启停菜单")
    private R<IdVo> enabled(@Validated @RequestBody EnabledParam enabledParam) {
        return menuService.enabled(enabledParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除菜单")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return menuService.delete(idParam);
    }

    @PostMapping(value = "saveRoleMenu")
    @ApiOperation(value = "保存角色菜单")
    private R<IdListVo> saveRoleMenu(@Validated @RequestBody RoleMenuParam roleMenuParam) {
        return menuService.saveRoleMenu(roleMenuParam);
    }

    @PostMapping(value = "listByRole")
    @ApiOperation(value = "获取角色菜单")
    private R<List<MenuVo>> listByRole(@Validated @RequestBody IdParam idParam) {
        return menuService.listByRole(idParam);
    }

}
